﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Specialized;
using System.Web.UI.WebControls;
using System.Xml.Linq;
using Anthony.Library;
using Formsy.Common;
using System.IO;

namespace Formsy.Providers.FileSystem
{
    public class StandardProvider : FileSystemProvider
    {
        public override void Initialize(string name, NameValueCollection config)
        {
            base.Initialize(name, config);
        }


        

        /// <summary>
        /// Saves a files.
        /// </summary>
        /// <returns></returns>
        public override List<FormsyFile> Save(string formName, int entryId, List<FormsyFile> files, string folderPath)
        {
            foreach (var f in files)
            {
                // create filename
                string filename = entryId.ToString() + "_" + f.FieldName + "." + f.Extension;

                // save full filename path
                f.Filename = folderPath + filename;

                // save the file
                FileSystemLibrary.SaveFile(folderPath, filename, f.Bytes);
                
            }

            return files;
        }

    }
}
